﻿<?php
if ($level != 3) {
	echo "Bạn không có quyền vào trang này.";
	exit();
}
if($search) {
	$search 	=  utf8_to_ascii($search);
	$sql_where 	= "WHERE album_name_ascii LIKE '%".$search."%'";
}
$num = $mysql->query("SELECT * FROM ".$tb_prefix."album $sql_where");
$total = $mysql->num_rows($num);
if($total) {
	$m_per_page = 30;
	if (!$pg) $pg = 1;
	$sql = "SELECT * FROM ".$tb_prefix."album $sql_where ORDER BY album_id DESC LIMIT ".(($pg-1)*$m_per_page).",".$m_per_page;
	$query = $mysql->query($sql);
		while($row = $mysql->fetch_array($query)) {
			$album_ID		=	$row['album_id'];
			$album_NAME		=	$row['album_name'];
			$album_IMG		=	$row['album_img'];
			$album_IMG		=	($album_IMG)?"<img src=".$album_IMG." width=50 height=50>":'';	
			$view_pages 	= 	admin_viewpages($total,$m_per_page,$pg);	
			$album_HTML	   .=	"<tr><td><input class=checkbox type=checkbox id=checkbox onclick=docheckone() name=checkbox[] value=$album_ID></td><td class=fr><b><a href=?act=album&mode=edit&id=".$album_ID.">".$album_NAME."</a></b></td><td class=fr_2 align=center>".$album_IMG."</td></tr>";		
		}
}
if(!$total) {
	$album_HTML = "<tr><td></td><td align=center>Chua có Album</td></tr>";
}
elseif ($_POST['do']) {
	$arr = $_POST['checkbox'];
	if (!count($arr)) die('Lỗi');
	if ($_POST['selected_option'] == 'del') {
		$in_sql = implode(',',$arr);
		$mysql->query("DELETE FROM ".$tb_prefix."album WHERE album_id IN (".$in_sql.")");
		echo "<script language='JavaScript'>{ window.parent.location='?act=list_album' }</script>";
	}
}
include("templates/list_album.html");
?>